/**
 * 
 */
package ru.cargobroker.workbench.services.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import ru.cargobroker.workbench.itest.BaseITests;
import ru.cargobroker.workbench.registry.domain.PerspectiveDescriptor;
import ru.cargobroker.workbench.registry.mock.MockPerspectiveDescriptor;
import ru.cargobroker.workbench.registry.services.PerspectiveRegistry;

/**
 * @author M.Frendiy
 * @since 0.1.0
 */
public class PerpspectiveRegistryTest extends BaseITests {
	
	private PerspectiveRegistry perspectiveRegistry;
	
	@Test
	public void testFindPerspectiveById() {
		MockPerspectiveDescriptor descriptor = new MockPerspectiveDescriptor();
		perspectiveRegistry.addPerspective(descriptor);
		
		PerspectiveDescriptor perspectiveById = perspectiveRegistry.findPerspectiveById(descriptor.getId());
		
		assertNotNull("Perspective must be not null", perspectiveById);
	}
	
	@Test
	public void testAddDuplicatPerspective() {
		MockPerspectiveDescriptor descriptor = new MockPerspectiveDescriptor();
		MockPerspectiveDescriptor descriptor2 = new MockPerspectiveDescriptor();
		perspectiveRegistry.addPerspective(descriptor);
		perspectiveRegistry.addPerspective(descriptor2);
		
		List<PerspectiveDescriptor> perspectives = perspectiveRegistry.getPerspectives();
		
		assertEquals("Must be only one perspective", 1, perspectives.size());
	}
	

	public PerspectiveRegistry getPerspectiveRegistry() {
		return perspectiveRegistry;
	}

	@Autowired
	public void setPerspectiveRegistry(PerspectiveRegistry perspectiveRegistry) {
		this.perspectiveRegistry = perspectiveRegistry;
	}
}
